package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;

@Mapper
public interface UserMapper {

    @Select("select id, openid,name, phone,sex, id_number, avatar, create_time" +
            " from user where openid = #{openid}")
    public User selectByOpenid(String openid);

    /***
     * useGeneratedKeys: 获取自增主键
     * keyProperty： 把自增的值赋值给哪一个字段
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into user(openid,create_time)values(#{openid}, #{createTime})")
    int insert(User user);

    @Select("select * from user where id = #{userId}")
    User selectById(Long userId);

    int countByCreateTime(LocalDateTime startTime, LocalDateTime endTime);
}
